<?php
require_once ("../src/db/connectdatabase.php");

function getBankLoanDetail($idbloan) {
	$con = new ConnectDB();
	$tbl = "banksloan";
	$fn = array('bankloan_id', 'loan_id', 'dac_tinh_loan', 'object_dk_loan', 'thu_tuc_loan', 'bankid', 'bankname', 'banklogo', 'datecreate');
	$fcon = array('bankloan_id' => $idbloan);
	$flike = array();
	return $con -> getvalueall($tbl,$fn,$fcon,$flike,'datecreate');
}


if(isset($_GET['as'])) {
	$check = true;
	$idloan = $_GET['as'];
	if($idloan == "vay_ca_nhan") {
		$vayname = "Vay Cá Nhân";
	} else if($idloan == "vay_tra_gop") {
		$vayname = "Vay Trả Góp";
	} else if($idloan == "vay_the_chap") {
		$vayname = "Vay Thế Chấp";
	} else {
		$check = false;
	}
	
	if($check) {
		if(isset($_GET['id'])) {
			$id = $_GET['id'];
			$arrbankloan = getBankLoanDetail($id);
			if(count($arrbankloan) > 0) {
		?>
<h3>Chi Tiết Ngân Hàng Cho <?php echo($vayname) ?></h3>
<div class="detailbankloan">
	<form action="" method="post" onSubmit="">
        <table border="1" cellpadding="0" cellspacing="0" width="850px;">
            <tr>
                <th valign="top" width="150px;">Ngân Hàng</th>
                <td valign="top"><strong><?php echo($arrbankloan[0][6]) ?></strong> &nbsp; &nbsp; <img src="../<?php echo($arrbankloan[0][7]) ?>" title="<?php echo($arrbankloan[0][6]) ?>"/></td>
            </tr>
            <tr>
                <th valign="top">Đặc Tính Cho Vay</th>
                <td style="padding-left:20px; padding-top:10px; padding-right:10px; padding-bottom:10px;"><?php echo($arrbankloan[0][2]) ?></td>
            </tr>
            <tr>
                <th valign="top">Đối Tượng-ĐK Vay</th>
                <td style="padding-left:20px; padding-top:10px; padding-right:10px; padding-bottom:10px;"><?php echo($arrbankloan[0][3]) ?></td>
            </tr>
            <tr>
                <th valign="top">Thủ Tục Cho Vay</th>
                <td style="padding-left:20px; padding-top:10px; padding-right:10px; padding-bottom:10px;"><?php echo($arrbankloan[0][4]) ?></td>
            </tr>
            <tr>
                <th colspan="2"><input value="Chỉnh Sửa" type="button" class="editdetailbankloan" idbloan="<?php echo($id) ?>"style="border-radius: 5px; padding:5px; width:100px; background:#03F; color:#FFF; font-weight:bold;" /><input value="Xóa" type="button" class="deletedetailbankloan" idbloan="<?php echo($id) ?>"style="border-radius: 5px; padding:5px; width:100px; background:#03F; color:#FFF; font-weight:bold;" /></th>
            </tr>
        </table>
    </form>
</div>
<script>
	$(document).on('click', '.editdetailbankloan', function(e) {
		elem = $(this)
		var idbloan = elem.attr('idbloan');
		window.location= 'admin.php?content=quanlivay&&as=<?php echo($idloan) ?>&&adrt=editbankloan&&id=' + idbloan;
	});
	
	$(document).on('click', '.deletedetailbankloan', function() {
		elem = $(this)
		var idbloan = elem.attr('idbloan');
		if(confirm("Bạn có muốn xóa?")) {
			$.ajax({
				url: "../src/ajax/ajaxbankloan.php",
				type: "post",
				data: {act:'del', idre: idbloan},
				dataType:"json",
				success: function(data) {
					if(data == true) {
						window.location= 'admin.php?content=quanlivay&&as=<?php echo($idloan) ?>&&adrt=viewbankloanall';
					} else {
						alert("Cập nhật dữ liệu không thành công");
					}
				}
			});
		}
	});
</script>
		<?php
			}
		}
	}
}

?>